package com.banciyuan.bcywebview.utils.baidussp;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/**
 * Created by squall1989 on 2017/2/20.
 */

public class SspUtils {

    public static List<NameValuePair> parseParams(Context var0, String var1) {
        ArrayList var2 = new ArrayList();
        var2.add(new BasicNameValuePair("v", "1.3"));
        var2.add(new BasicNameValuePair("adPosition", var1));
        var2.add(new BasicNameValuePair("device", Build.MODEL));
        String var3 = "_";

        String var4;
        try {
            if (c(var0, "android.permission.READ_PHONE_STATE")) {
                var4 = ((TelephonyManager) var0.getSystemService(var0.TELEPHONY_SERVICE)).getDeviceId();
                var3 = var3 + var4;
            }

            if (c(var0, "android.permission.ACCESS_WIFI_STATE")) {
                var4 = ((WifiManager) var0.getSystemService(var0.WIFI_SERVICE)).getConnectionInfo().getMacAddress();
                var3 = var4 + var3;
            }

            var3 = EncrptUtils.a(var3);
        } catch (Exception var12) {
            var12.printStackTrace();
        }

        var2.add(new BasicNameValuePair("u", var3));
        var4 = "";

        int var7;
        try {
            ConnectivityManager var5 = (ConnectivityManager) var0.getSystemService(var0.CONNECTIVITY_SERVICE);
            NetworkInfo var6 = var5.getActiveNetworkInfo();
            if (var6 != null) {
                if (var6.getType() == 1) {
                    var4 = "WIFI";
                } else if (var6.getType() == 0) {
                    var7 = a(var6.getSubtype());
                    if (var7 == 1) {
                        var4 = "2G";
                    } else if (var7 == 2) {
                        var4 = "3G";
                    } else if (var7 == 3) {
                        var4 = "4G";
                    }
                }
            }
        } catch (Exception var11) {
            var11.printStackTrace();
        }

        var2.add(new BasicNameValuePair("net", var4));

        try {
            DisplayMetrics var13 = var0.getResources().getDisplayMetrics();
            int var15 = var13.widthPixels;
            var7 = var13.heightPixels;
            var2.add(new BasicNameValuePair("sw", "" + var15));
            var2.add(new BasicNameValuePair("sh", "" + var7));
        } catch (Exception var10) {
            var10.printStackTrace();
        }

        var2.add(new BasicNameValuePair("sys", "android " + Build.VERSION.RELEASE));
        var2.add(new BasicNameValuePair("lang", Locale.getDefault().getLanguage()));
        String var14 = var0.getPackageName();
        var2.add(new BasicNameValuePair("app", var14));

        try {
            PackageManager var16 = var0.getPackageManager();
            PackageInfo var17 = var16.getPackageInfo(var14, 0);
            String var8 = var17.versionName;
            var2.add(new BasicNameValuePair("appv", var8));
        } catch (Exception var9) {
            var9.printStackTrace();
        }

        return var2;
    }

    public static int a(int var0) {
        switch (var0) {
            case 1:
            case 2:
            case 4:
            case 7:
            case 11:
                return 1;
            case 3:
            case 5:
            case 6:
            case 8:
            case 9:
            case 10:
            case 12:
            case 13:
            case 14:
                return 2;
            case 15:
                return 3;
            default:
                return 0;
        }
    }

    public static boolean c(Context var0, String var1) {
        boolean var2 = var0.checkCallingOrSelfPermission(var1) != PackageManager.PERMISSION_DENIED;
        return var2;
    }


}
